home *** CD-ROM | disk | FTP | other *** search
- /**
- -- Graphics Shell.c (modified)
- --
- -- This file is a shell that can be used to build "new" Graphics applications.
- -- It contains all of the required calls to use the "new" Graphics routines and
- -- QuickDraw (i.e. windows) together. It will put up one window. You "quit"
- -- the application by clicking in the close bix. This shell does not use a menu.
- --
- -- The application is expected to supply the following functions which are called
- -- by this shell:
- --
- -- void DoInitialization(WindowPtr);
- -- void DoDraw(WindowPtr);
- -- void DoDispose(WindowPtr);
- -- void DoClick(WindowPtr);
- -- void DoIdle(WindowPtr);
- --
- --
- -- Change History:
- --
- -- 3/90 New
- -- 6/91 Updated the shell to reflect the changes in "Graphics" v1.0d21.2. PLA
- -- 6/92 Made the following variables global: gDebugging, gGiveMeValidation,gGraphicsHeapSize.
- -- See the comments for detail in this file.
- -- 6/92 Added printing guts, mangled and reorganized. DMH
- -- 9/93 Updated files to work with the ß2 "GXified" interface files. PLA
- -- 9/93 Added override for gxPrintingEvent to handle update events. DMH
- -- 9/93 Added GXUpdateJob for resume events. DMH
- -- 5/94 gxPrintingEvent override now ignores appropriate events. DMH
- -- 8/94 Universalized. DMH
- --
- -- © Apple Computer, Inc. 1990 - 1993 All rights reserved
- --
- **/
-
-
- #include <Desk.h>
- #include <Events.h>
- #include <Fonts.h>
- #include <Windows.h>
- #include <Memory.h>
- #include <ToolUtils.h>
- #include <Menus.h>
- #include <Quickdraw.h>
-
- #include "PrintingManager.h"
- #include "graphics toolbox.h"
- #include "graphics routines.h"
- #include "graphics libraries.h"
- #include "graphics debugging.h"
- #include "graphics shell.h"
-
- #define kOSEvent app4Evt /* event used by MultiFinder */
- #define kSuspendResumeMessage 1 /* high byte of suspend/resume event message */
- #define kResumeMask 1 /* bit of message field for resume vs. suspend */
-
- Boolean gQuitting;
- long gSleep = 0;
-
- /*------ main -----------------------------------------------------------------------------------------*/
-
- void main()
- {
- CursHandle theCurs;
- Handle menuBar;
- gxGraphicsClient client;
- OSErr err;
- WindowPtr wind;
-
- /**
- The GXNewGraphicsClient routine defines the graphics heap size. If you do not make this call,
- the GX graphics engine will create this heap automatically. How? It will create a heap which
- is a percentage of your application's ideal memory foot print. This call allows you to explicity
- define the ammount of memory used by the graphics system for it's graphics objects heap.
- **/
- client = GXNewGraphicsClient(nil, gGraphicsHeapSize * 1024, 0L);
-
- /** Generic heap initialization. **/
- MaxApplZone();
- MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters();
-
- /**
- If gDebugging = TRUE, you will receive graphics library errors & notices will be posted. This
- functionality will only work with the "debugging" version of the QuickDraw GX init. If this
- init is not installed, these functions will not work.
- **/
- if (gDebugging) {
- SetGraphicsLibraryErrors ();
- SetGraphicsLibraryNotices();
- }
-
- /**
- Set "gGiveMeValidation" to TRUE, if you want run-time validation. As you increase the amount
- of validation, The drawing speed will SLOW down due to all of the internal checking.
-
- gxPublicValidation will check parameters to public routines. For additional details regarding
- the various levels of validation, please see the documentation.
- **/
- if (gGiveMeValidation) GXSetValidation(gxPublicValidation);
-
-
- /** initialize the new graphics and printing environments. **/
-
- GXEnterGraphics();
- err = GXInitPrinting();
-
- /** initialize the other managers, if no errors occured. **/
-
- if (!err)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitCursor();
-
- theCurs = GetCursor(watchCursor);
- SetCursor(*theCurs);
-
- menuBar = GetNewMBar(rMenuBar); /* Create the menu bar */
-
- if (menuBar)
- {
- gQuitting = false;
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
- AddResMenu(GetMHandle(mApple), 'DRVR'); /* add Apple Menu items */
- DrawMenuBar();
-
- // We gxInitialize the CommonColors Library. This will allow us to set the color of a
- // shape by calling the SetShapeCommonColor function. We will need to call
- // DisposeCommonColors when we leave, to clean up the world.
-
- InitCommonColors();
-
- DoCreateNew();
- SetCursor(&qd.arrow);
-
- while (!gQuitting)
- {
- EventLoop();
- DoIdle(wind);
- }
-
-
- // Leaving. Close all the windows so we get rid of any data we or GX created. Then,
- // dispose of the common colors and exit the GX printing and graphics environment.
-
- while (wind = FrontWindow())
- DoDispose(wind);
-
- DisposeCommonColors();
- }
-
- GXExitPrinting(); /** Close the new printing mgr. **/
- }
-
- GXExitGraphics(); /** Deallocate all of the default structures **/
- GXDisposeGraphicsClient(client);
- }
-
-
- /*------ MyPrintingEventOverride -----------------------------------------------------------------------------*/
- // Override for GXPrintingEvent. It allows us to update our windows
- // when the moveable modal printing dialogs are moved.
-
- OSErr MyPrintingEventOverride(EventRecord *anEvent, Boolean filterEvent)
- {
- OSErr err = noErr;
-
- // Handle events in whatever way is appropriate. MyDoEvent is our
- // generic event handler. We don't pass it events that it shouldn't
- // handle while print dialogs are displayed.
-
- if (!filterEvent)
- switch (anEvent->what)
- {
- case mouseDown:
- case keyDown:
- case autoKey:
- break;
-
- default:
- MyDoEvent(anEvent);
- }
-
- return err;
- }
-
-
- /*------ EventLoop ------------------------------------------------------------------------------------*/
-
- void EventLoop()
- {
- EventRecord theEvent;
-
- if (WaitNextEvent(everyEvent, &theEvent, gSleep, nil))
- MyDoEvent(&theEvent);
- }
-
-
-
- /*------ MyDoEvent ------------------------------------------------------------------------------------*/
-
- void MyDoEvent(EventRecord *theEvent)
- {
- char key;
- WindowPtr whichWindow;
- GrafPtr oldPort;
-
- switch(theEvent->what)
- {
- case updateEvt:
- if (((WindowPeek) theEvent->message)->windowKind == userKind)
- {
- GetPort(&oldPort);
- SetPort((WindowPtr) theEvent->message);
- BeginUpdate((WindowPtr) theEvent->message);
- DoDraw((WindowPtr) theEvent->message);
- EndUpdate((WindowPtr) theEvent->message);
- SetPort(oldPort);
- }
- break;
-
- case mouseDown:
- switch (FindWindow(theEvent->where, &whichWindow)) {
- case inSysWindow:
- SystemClick(theEvent, whichWindow);
- break;
-
- case inDrag:
- if (((WindowPeek) whichWindow)->windowKind == userKind)
- DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds);
- break;
-
- case inGoAway:
- if (((WindowPeek) whichWindow)->windowKind == userKind)
- {
- if (TrackGoAway(whichWindow, theEvent->where))
- DoDispose(whichWindow);
- }
- break;
-
- case inContent:
- if ((whichWindow != FrontWindow()) &&
- (((WindowPeek) whichWindow)->windowKind == userKind))
- SelectWindow(whichWindow);
- break;
- case inMenuBar:
- DoMenuCommand(MenuSelect(theEvent->where));
- break;
-
- }
-
- case keyDown:
- case autoKey:
- key = theEvent->message & charCodeMask;
- if (theEvent->modifiers & cmdKey)
- if (theEvent->what == keyDown)
- DoMenuCommand(MenuKey(key));
- break;
-
-
- case kOSEvent:
- switch ((unsigned long) theEvent->message >> 24) { /** high byte of message **/
- case kSuspendResumeMessage: /** suspend/resume is also an activate/deactivate **/
- if ((theEvent->message & kResumeMask) == 0)
- gSleep = 80; /** we are headed to the background, so slow down... **/
- else
- {
- gSleep = 0; /** we are headed to the foreground, so speed up... **/
-
- // On a resume event, we need to call GXUpdateJob on all of our documents'
- // jobs. This is important because the user may have just changed
- // something which affects our jobs (like the size of the paper in the
- // printer).
- //
- // Since our application stores our document references in the refCon fields
- // of our documents' windows, we just loop through every one of our windows,
- // extract our document pointers and update the associated jobs.
-
- whichWindow = FrontWindow();
-
- while (whichWindow != nil)
- {
- if (((WindowPeek) whichWindow)->windowKind == userKind)
- GXUpdateJob(GetDocJob(whichWindow));
-
- whichWindow = (WindowPtr) ((WindowPeek) whichWindow)->nextWindow;
- }
- }
- break;
- }
- break;
- }
- }
-
-